package ex.datastream.functions.function;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.util.Collector;

/**
 * 按空格、不区分大小写进行拆分，返回拆分后的数据
 */
public class FlatMapFuncBySplitter01 implements FlatMapFunction<String, Tuple2<String,Integer>> {

        @Override
        public void flatMap(String value, Collector<Tuple2<String, Integer>> out)  {
            System.out.print(value);
            String[]tokens=value.toLowerCase().split("\\W+");
            for(String token:tokens){
                if(token.length()>0){
                    out.collect(new Tuple2<String,Integer>(token,1));
                }
            }
        }
}
